package com.platform.controller;

import com.platform.entity.TeamWithUserEntity;
import com.platform.entity.TeamWithUserEntityVO;
import com.platform.service.TeamWithUserService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 推广管理:团队管理列表
 *
 */
@RestController
@RequestMapping("teamwithuser")
public class TeamWithUserController {
    @Autowired
    private TeamWithUserService teamWithUserService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("teamwithuser:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<TeamWithUserEntityVO> teamwithuserList = teamWithUserService.queryListVO(query);
        int total = teamWithUserService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(teamwithuserList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("teamwithuser:info")
    public R info(@PathVariable("userId") Long userId) {
        TeamWithUserEntity teamwithuser = teamWithUserService.queryObject(userId);

        return R.ok().put("teamwithuser", teamwithuser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("teamwithuser:save")
    public R save(@RequestBody TeamWithUserEntity teamwithuser) {
        teamWithUserService.save(teamwithuser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("teamwithuser:update")
    public R update(@RequestBody TeamWithUserEntity teamwithuser) {
        teamWithUserService.update(teamwithuser);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("teamwithuser:delete")
    public R delete(@RequestBody Long[] userIds) {
        teamWithUserService.deleteBatch(userIds);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<TeamWithUserEntity> list = teamWithUserService.queryList(params);

        return R.ok().put("list", list);
    }
}
